package com.example.blog.Service;

import com.example.blog.mapper.BlogInfoMapper;
import com.example.blog.mapper.UserInfoMapper;
import com.example.blog.model.BlogInfo;
import com.example.blog.model.UserInfo;
import io.jsonwebtoken.lang.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    UserInfoMapper userInfoMapper;
    @Autowired
    BlogInfoMapper blogInfoMapper;
    public  UserInfo selectByName(String username) {
        return userInfoMapper.selectByName(username);
    }

    public UserInfo getUserInfoById(int userId) {
       return userInfoMapper.selectById(userId);
    }

    public UserInfo getAuthorInfoByBlogId(Integer blogId) {
        BlogInfo blogInfo = blogInfoMapper.selectById(blogId);
        Assert.notNull(blogInfo,"不存在该博客");
        UserInfo userInfo = userInfoMapper.selectById(blogInfo.getUserID());
        return userInfo;
    }
}
